/******************************************************************************
 * @File name   :      remindUtils.java
 *
 * @Author      :      JIZHANGS
 *
 * @Date        :      Dec 8, 2015
 *
 * @Copyright Notice: 
 * Copyright (c) 2015 Capgemini, Inc. All  Rights Reserved.
 * This software is published under the terms of the Capgemini Software
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file.
 * 
 * 
 * ----------------------------------------------------------------------------
 * Date                   Who         Version        Comments
 * Dec 8, 2015 1:24:25 PM        JIZHANGS     1.0            Initial Version
 *****************************************************************************/
package com.cap.bts.crmdp.dealer.remind.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 *
 */
public class RemindUtils {
    /**  
     * 计算两个日期之间相差的天数  
     * @param smdate 较小的时间 
     * @param bdate  较大的时间 
     * @return 相差天数 
     * @throws ParseException  
     */    
    public static int daysBetween(Date smdate,Date bdate) throws ParseException{    
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
        smdate=sdf.parse(sdf.format(smdate));  
        bdate=sdf.parse(sdf.format(bdate));  
        Calendar cal = Calendar.getInstance();    
        cal.setTime(smdate);    
        long time1 = cal.getTimeInMillis();                 
        cal.setTime(bdate);    
        long time2 = cal.getTimeInMillis();         
        long betweenDays=(time2-time1)/(1000*3600*24);  
            
       return Integer.parseInt(String.valueOf(betweenDays));           
    }    
    
    /**  
     * 计算两个日期之间相差的天数  
     * @param smdate 较小的时间 
     * @param bdate  较大的时间 
     * @return 相差天数 
     * @throws ParseException  
     */    
    public static int days2TodayBetween(Date smdate) throws ParseException{    
        Date bdate=null;
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
        smdate=sdf.parse(sdf.format(smdate));  
        bdate=sdf.parse(sdf.format(new Date()));  
        Calendar cal = Calendar.getInstance();    
        cal.setTime(smdate);    
        long time1 = cal.getTimeInMillis();                 
        cal.setTime(bdate);    
        long time2 = cal.getTimeInMillis();         
        long betweenDays=(time2-time1)/(1000*3600*24);  
            
       return Integer.parseInt(String.valueOf(betweenDays));           
    }  
      
/** 
*字符串的日期格式的计算 
*/  
    public static int daysBetween(String smdate,String bdate) throws ParseException{  
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
        Calendar cal = Calendar.getInstance();    
        cal.setTime(sdf.parse(smdate));    
        long time1 = cal.getTimeInMillis();                 
        cal.setTime(sdf.parse(bdate));    
        long time2 = cal.getTimeInMillis();         
        long betweendays=(time2-time1)/(1000*3600*24);  
            
       return Integer.parseInt(String.valueOf(betweendays));     
    }  
    
    /** 
    *字符串的日期格式的计算 
    */  
        public static long days2TodayBetween(String smdate) throws ParseException{  
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
            Calendar cal = Calendar.getInstance();    
            cal.setTime(sdf.parse(smdate));    
            long time1 = cal.getTimeInMillis();                 
            cal.setTime(new Date());    
            long time2 = cal.getTimeInMillis();         
            long betweenDays=(time2-time1)/(1000*3600*24);  
                
           return Math.abs(betweenDays);     
        }  
        
        /** 
         *字符串的日期格式的计算 
         */  
         public static String beforeTodayDays2Date(String days) throws ParseException{  
             java.util.Date myDate = new java.util.Date();
             myDate.setTime(((new java.util.Date().getTime() / 1000) - 60 * 60 * 24 * Long.parseLong(days))*1000);
             SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
            return sdf.format(myDate);     
         }  
         
         /** 
          *字符串的日期格式的计算 
          */  
          public static String afterTodayDays2Date(String days) throws ParseException{  
              java.util.Date myDate = new java.util.Date();
              myDate.setTime(((new java.util.Date().getTime() / 1000) + 60 * 60 * 24 * Long.parseLong(days))*1000);
              SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
             return sdf.format(myDate);     
          } 

}
